package cn.tqfeiyang.springplus.generator.util;

import java.util.Set;

public class Pluralizer {

    // 一些需要特殊处理的单词列表
    private static final Set<String> IRREGULAR_PLURALS = Set.of("person", "man", "child");

    // 一些单词通过添加's'转换为复数形式
    private static final Set<String> REGULAR_PLURALS = Set.of("tomato", "potato", "analysis");

    public static String toPlural(String word) {
        if (word == null || word.isEmpty()) {
            return word;
        }

        // 特殊规则处理
        if (IRREGULAR_PLURALS.contains(word)) {
            return word + "ren"; // 假设这些单词都以'ren'结尾
        }

        // 常规规则处理
        if (word.endsWith("s") || word.endsWith("x") || word.endsWith("z") || word.endsWith("ch") || word.endsWith("sh")) {
            return word + "es";
        } else if (word.endsWith("y")) {
            return word.substring(0, word.length() - 1) + "ies";
        } else {
            return word + "s";
        }
    }
}
